<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;

class FavModel extends ToyModel
{
    protected $table = 'Ufavorite';
    protected $guarded = [];
    public $timestamps = false;


    /**
     * 获取模型
     * @param $request
     * @return mixed
     */
    public static function getModel($request): mixed
    {
        $Model = self::where('Status', 1);
        if ($request->input('CID'))
            $Model = $Model->where('CID', $request->input('CID'));
        if ($request->input('PID'))
            $Model = $Model->where('PID', $request->input('PID'));
        if ($request->input('uid'))
            $Model = $Model->where('uid', $request->input('uid'));
        return $Model;
    }

    public function goods(): BelongsTo
    {
        return $this->belongsTo(GoodsPicPrimaryModel::class, 'PID', 'ID');
    }
}
